﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Windows.Forms;

namespace LyncOutlookOpenService
{
    class Program
    {
        static void Main()
        {

            bool isOutlookOpen = false;
            bool isLyncOpen = false;
            int lyncProcessCount = 0;

            Process[] procs = Process.GetProcesses();

            foreach (Process proc in procs)
            {
                string procName = proc.ProcessName.ToLower();
                if (procName == "outlook")
                {
                    isOutlookOpen = true;
                }
                else if (procName == "communicator")
                {
                    lyncProcessCount++;
                }
            }

            if (lyncProcessCount >= 2)
            {
                isLyncOpen = true;
            }

            if (!isLyncOpen)
            {
                string path = @"C:\Program Files (x86)\Microsoft Lync\communicator.exe";
                string msg = "It seems your Lync is not running. Would you like to open it?";
                DialogResult res = MessageBox.Show(msg, "Open Lync?", MessageBoxButtons.YesNo);
                if (res == DialogResult.Yes)
                {
                    Process.Start(path);
                }
            }

            if (!isOutlookOpen)
            {
                string path = @"C:\Program Files (x86)\Microsoft Office\Office14\OUTLOOK.EXE";
                string msg = "It seems your Outlook is not running. Would you like to open it?";
                DialogResult res = MessageBox.Show(msg, "Open Outlook?", MessageBoxButtons.YesNo);
                if (res == DialogResult.Yes)
                {
                    Process.Start(path);
                }
            }

            
        }
    }
}
